home *** CD-ROM | disk | FTP | other *** search
- %BEGIN Text
-
- % Copyright (C) 1993 David John Burrowes
- % Distributed under terms of GNU General Public License.
- % See COPYING.text in Convert PICT's CommentedPSCode for a copy
-
- %
- % The current text drawing position
- %
- /textY 0 def
- /textX 0 def
- %
- % Extra width used when printing spaces
- %
- /extraSpaceWidth 0 def
- /extraCharWidth 0 def
- %
- % Establish default font
- %
- /typeSize 12 def
- /Chicago findfont
- typeSize scalefont
- setfont
- %
- % the x and y scaling factors
- %
- /xscale 1 def
- /yscale 1 def
- %
- % Style flags (true eq use that style)
- %
- /macBold false def
- /macItalic false def
- /macUnderline false def
- /macOutline false def
- /macShadow false def
- /macCondense false def
- /macExtend false def
- %
- % Mode
- %
- /textMode /srcCopy def
- %
- % For PicComment processing
- %
- /suppressText false def
- /textCenterX 0 def
- /textCenterY 0 def
- /textAngle 0 def
- /rotateText false def
-
- %%%%%%%%%%%%%
- % Name: drawChar
- % Syntax: string drawChar -
- % About: Draws specifid string, This should only be called by PICTshow, as it depends on
- % values set up there.
- %%%%%%%%%%%%%
- /drawChar
- {
- textMatrix setmatrix
- show
- originalMatrix setmatrix
- }
- def
-
- %%%%%%%%%%%%%
- % Name: pathNonZero
- % Syntax: - pathNonZero bool
- % About: returns true if current path has a non-zero height
- %%%%%%%%%%%%%
- /pathNonZero
- {
- pathbbox
- /top exch def
- pop
- /bottom exch def
- pop
-
- top bottom sub 0 eq
- {false}
- {true}
- ifelse
- }
- def
-
- %%%%%%%%%%%%%
- % Name: PICTshow
- % Syntax: x y string PICTshow -
- % About: Draw the specified text at x,y. theString is drawn one char at a time because
- % this provides better control when drawing the various type styles.
- % The various styles are drawn to emulate on-screen mac drawing. Thus, italics are
- % obliqued, bold is double-printed (slightly offset). Condensed and Extended have
- % altered spacing, but characters are not drawn thin or fat. Etc.
- % Bugs:
- % Bold outlines and shadows have a doubled left border.
- % Shadowed char extending to *left* will place shadow on neighbor, not behind
- % extend values not well defined on Mac. I've made good approximations here.
- %%%%%%%%%%%%%
- /PICTshow
- {
- /theString exch def
- /y exch def
- /x exch def
- /extend 0 def % extra space to widen each char
- /charString 1 string def % holds char as a string
-
- suppressText false eq
- {
- gsave
- %
- % Immediately rotate our coordinate space if the rotateText flag is true.
- % Warning: The matrix stuff seems to overwite some of this. ICK.
- %
- rotateText true eq
- { textAngle rotate }
- if
-
- /originalMatrix matrix currentmatrix def
- %
- % Build a matrix to use when drawing text: make it upside down (-1) so text will
- % appear rightside up, slant it (.5) if doing 'italic', and scale by the
- % scaling factors. (I dislike this explicit 'putting' of values into the matrix...
- % it may mess up the image in some cases. The .5 put seems needed to get
- % around a NS 3.1 Preview bug though.
- %
- /textMatrix
- xscale yscale matrix currentmatrix scale
- dup 3
- matrix currentmatrix 3 get
- -1 mul put
- macItalic true eq
- { dup 2 .5 put }
- if
- def
- %
- % Store ammount to extend width of each char by
- %
- macBold true eq
- {/extend extend 1.5 add def }
- if
-
- macOutline true eq
- { /extend extend 2 add def }
- if
-
- macExtend true eq
- {/extend extend 2 add def }
- if
-
- macShadow true eq
- {/extend extend 2 add def }
- if
-
- macCondense true eq
- {/extend extend 2 sub def }
- if
- %
- % For each character in string, draw it...
- %
- foregroundColor useColor
- theString
- {
- %
- % Define next char of theString, width of the char, and extra space
- % to add to this character.
- %
- /theChar exch def
- charString 0 theChar put
- /charWidth charString stringwidth pop def % pop y dimen
- 32 theChar eq
- { /extraSpace extraSpaceWidth def }
- { /extraSpace extraCharWidth def }
- ifelse
- %
- % Draw a shadow
- %
- macShadow true eq
- {
- x 2 add y 2 add moveto % move down & right to draw shadow
- charString drawChar
- macBold true eq
- {
- x 3 add y 2 add moveto
- charString drawChar
- }
- if
- }
- if
- %
- % Draw other text. If doing bold, loop twice, incrementing boldStep
- % second time to produce the double-print of bold.
- %
- /boldstep 0 def
- macBold true eq {2} {1} ifelse % loop 2ce if bold is on.
- {
- %
- % If doing shadow or outline, draw the text in white with black outline
- % unless path has no height (maybe it's a bitmap), draw the char normal
- %
- macShadow true eq macOutline true eq or
- {
- newpath
- x boldstep add y moveto
- textMatrix setmatrix
- charString true charpath
- originalMatrix setmatrix
- pathNonZero true eq
- {
- 1 setgray
- fill
- foregroundColor useColor
-
- newpath
- x boldstep add y moveto
- textMatrix setmatrix
- charString false charpath
- originalMatrix setmatrix
- 0 setlinewidth
- stroke
- }
- {
- x boldstep add y moveto
- charString drawChar
- }
- ifelse
- }
- {
- x boldstep add y moveto
- charString drawChar
- }
- ifelse
- /boldstep boldstep 1 add def
- }
- repeat
- originalMatrix setmatrix
-
- macUnderline true eq
- {
- x y 1 add moveto
- x charWidth add extraSpace add extend add y 1 add lineto
- 1 setlinewidth
- stroke
- }
- if
- %
- % Increment x for the next character's start
- %
- /x x charWidth add extraSpace extend add add def
- }
- forall
- grestore
- }
- if % if we were to suppress writing text out.
- }
- def
-
- %%%%%%%%%%%%%
- % Name: txFont [0003]
- % Syntax: name txFont -
- % num txFont -
- % About: This sets the type family to draw text in. If param is not a
- % name, the converter could not identify the `font', so this
- % routine must decide what family to use.
- %%%%%%%%%%%%%
- /txFont
- {
- /family exch def
-
- family type /nametype eq
- {
- family findfont
- }
- {
- %
- % Convert the number to a font name
- %
- family 134 eq
- {/Linguistics findfont}
- {family 149 eq
- {/NewOrleans findfont}
- {family 64 eq
- {/Davids findfont}
- {/Chicago findfont} % default font
- ifelse}
- ifelse}
- ifelse
- }
- ifelse
-
- typeSize scalefont
- setfont
- }
- def
-
- %%%%%%%%%%%%%
- % Name: txFace [0004]
- % Syntax: array txFace -
- % About: Given an array of names, set several global flags to based on
- % them. These indicate what text styles to use when drawing text.
- %%%%%%%%%%%%%
- /txFace
- {
- /styleArray exch def
- /macBold false def
- /macItalic false def
- /macUnderline false def
- /macOutline false def
- /macShadow false def
- /macCondense false def
- /macExtend false def
- styleArray
- {
- /style exch def
- style /bold eq {/macBold true def}
- {style /italic eq {/macItalic true def}
- {style /underline eq {/macUnderline true def}
- {style /outline eq {/macOutline true def}
- {style /shadow eq {/macShadow true def}
- {style /condense eq {/macCondense true def}
- {style /extend eq {/macExtend true def}
- { % Actually, this is an error condition of some sort
- } ifelse
- } ifelse
- } ifelse
- } ifelse
- } ifelse
- } ifelse
- } ifelse
- }
- forall
- }
- def
-
- %%%%%%%%%%%%%
- % Name: txMode [0005]
- % Syntax: name txMode -
- % About: Sets the text drawing mode passed by caller. This is not used
- % so we just store it.
- % Note: if mode was unknown, we get /badMode-# (# is mode num))
- %%%%%%%%%%%%%
- /txMode
- { /textMode exch def }
- def
-
- %%%%%%%%%%%%%
- % Name: spExtra [000C]
- % Syntax: num spExtra -
- % About: Changes width of space character in future text drawing
- % operations.
- %%%%%%%%%%%%%
- /spExtra
- {/extraSpaceWidth exch def }
- def
-
- %%%%%%%%%%%%%
- % Name: txSize [000D]
- % Syntax: num txSize -
- % About: Sets the size of subsequent text to the passed number.
- % Do this by scaling relative to the current size.
- %%%%%%%%%%%%%
- /txSize
- {
- /newTypeSize exch def
- currentfont
- newTypeSize typeSize div scalefont
- setfont
- /typeSize newTypeSize def
- }
- def
-
- %%%%%%%%%%%%%
- % Name: TxRatio [0010]
- % Syntax: xscale yscale txRatio -
- % About: This sets a horozontal and vertical scaling factors for text
- % that is subsequently drawn.
- %%%%%%%%%%%%%
- /txRatio
- {
- /yscale exch def
- /xscale exch def
- }
- def
-
- %%%%%%%%%%%%%
- % Name: chExtra [0016]
- % Syntax: num chExtra -
- % About: The chExtra opcode probably sets the spacing between characters.
- % I couldn't confirm this, though, so this does nothing.
- %%%%%%%%%%%%%
- /chExtra
- {pop}
- def
-
- %%%%%%%%%%%%%
- % Name: longText [0028]
- % Syntax: num num string longText -
- % About: Displays the string at coords. Makes coords the new textX,Y
- %%%%%%%%%%%%%
- /longText
- {
- /theString exch def
- /textY exch def
- /textX exch def
-
- textX textY theString PICTshow
- }
- def
-
- %%%%%%%%%%%%%
- % Name: DHText [0029]
- % Syntax: num string DHText -
- % About: Displays string offset sideways from textX (positive is right)
- %%%%%%%%%%%%%
- /DHText
- {
- /theString exch def
- /deltaX exch def
-
- deltaX textX add textY theString longText
- }
- def
-
- %%%%%%%%%%%%%
- % Name: DVText [002A]
- % Syntax: num string DVText -
- % About: Displays string offset down from textY (positive is down)
- %%%%%%%%%%%%%
- /DVText
- {
- /theString exch def
- /deltaY exch def
- textX deltaY textY add theString longText
- }
- def
-
- %%%%%%%%%%%%%
- % Name: DHDVText [002B]
- % Syntax: num num string DVText -
- % About: Displays string offset from text X,Y (positive is down & right)
- %%%%%%%%%%%%%
- /DHDVText
- {
- /theString exch def
- /deltaY exch def
- /deltaX exch def
-
- deltaX textX add deltaY textY add theString longText
- }
- def
-
- %%%%%%%%%%%%%
- % Name: fontName [002C]
- % Syntax: name fontName -
- % About: Given the name of a type font, this calls txFont to actually process
- % the font name.
- %%%%%%%%%%%%%
- /fontName
- { txFont }
- def
-
-
- %%%%%%%%%%%%%
- % Name: lineJustify [002D]
- % Syntax: num num lineJustify -
- % About: Changes the extra width for normal characters (no spaces), and some
- % presently unknown value.
- %%%%%%%%%%%%%
- /lineJustify
- {
- pop
- /extraCharWidth exch def
- }
- def
-
- %END Text
-